<?php
namespace Admin\Controller;

use Common\Model\TreeModel;
use Common\Util\BaseData;
use Common\Util\GoodsData;
use Common\Util\UserData;

class ZsFormController extends AdminController{

	public function __construct(){
		parent::__construct();
	}

	public function complaint(){
		$this->assign('meta_title', '投诉文章');
		$t_user_cms_article_complaint = M("user_cms_article_complaint");
		$complaint_phone = trim($_GET['complaint_phone']);
		if(isset($complaint_phone) && !empty($complaint_phone)){
			$map['complaint_phone'] = ['like', "%$complaint_phone%"];
		}
		if(isset($_GET['status']) && !empty($_GET['status'])){
			if($_GET['status'] == -1){
				$map['status'] = 0;
			}else{
				$map['status'] = $_GET['status'];
			}
		}
		$page = I('page', 1, 'intval'); // 默认显示第一页数据
		$row = 20;
		$data = $t_user_cms_article_complaint
			->where($map)
			->order("id desc")
			->page($page, $row)
			->select();
		foreach($data as $key => $val){
			$user_info = UserData::getUserInfoById($val['user_id']);
			$data[$key]['user_headimg'] = $user_info['user_headimg'];
			$data[$key]['user_nickname'] = $user_info['user_nickname'];
		}
		/* 查询记录总数 */
		$count = $t_user_cms_article_complaint
			->where($map)
			->count();
		$list_data ['list_data'] = $data;
		// 分页
		if($count > $row){
			$page = new \Think\Page ($count, $row);
			$page->setConfig('theme', '%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
			$list_data ['_page'] = $page->show();
		}
		$this->assign('all_count', $count);
		$this->assign('list_data', $list_data);
		$this->assign('gget', $_GET);
		$this->display();
	}

	public function feedback(){
		$this->assign('meta_title', '反馈建议');
		$t_user_feedback = M("user_feedback");
		if(isset($_GET['status']) && !empty($_GET['status'])){
			if($_GET['status'] == -1){
				$map['status'] = 0;
			}else{
				$map['status'] = $_GET['status'];
			}
		}
		$page = I('page', 1, 'intval'); // 默认显示第一页数据
		$row = 20;
		$data = $t_user_feedback
			->where($map)
			->order("id desc")
			->page($page, $row)
			->select();
		foreach($data as $key => $val){
			$user_info = UserData::getUserInfoById($val['user_id']);
			$data[$key]['user_headimg'] = $user_info['user_headimg'];
			$data[$key]['user_nickname'] = $user_info['user_nickname'];
			$data[$key]['images'] = explode(',', $val['images']);
		}

		/* 查询记录总数 */
		$count = $t_user_feedback
			->where($map)
			->count();
		$list_data ['list_data'] = $data;
		// 分页
		if($count > $row){
			$page = new \Think\Page ($count, $row);
			$page->setConfig('theme', '%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
			$list_data ['_page'] = $page->show();
		}
		$this->assign('all_count', $count);
		$this->assign('list_data', $list_data);
		$this->assign('gget', $_GET);
		$this->display("feedback");
	}

	public function setStatus(){
		$field = I('get.field');
		$status = I('get.status');
		$aid = I('get.aid');
		$t_user_cms_article_complaint = M("user_cms_article_complaint");
		$data['id'] = $aid;
		$data[$field] = $status;
		$data['update_time'] = time();
		if($t_user_cms_article_complaint->save($data)){
			$this->return_json_data(1, '更新成功');
		}else{
			$this->return_json_data(0, '更新失败');
		}
	}
	public function setStatus1(){
		$field = I('get.field');
		$status = I('get.status');
		$aid = I('get.aid');
		$tuser_feedback = M("user_feedback");
		$data['id'] = $aid;
		$data[$field] = $status;
		$data['update_time'] = time();
		if($tuser_feedback->save($data)){
			$this->return_json_data(1, '更新成功');
		}else{
			$this->return_json_data(0, '更新失败');
		}
	}

}
